//
//  PABViewController.swift
//  swift各类控件集锦
//
//  Created by iosdev1 on 2017/5/23.
//  Copyright © 2017年 zyy. All rights reserved.
//

import UIKit

protocol ProtocolDelegate {
    func protocolDelegateFuncOne(val:String) -> Void
    func protocolDelegateFuncTwo(val:Dictionary<String, Any>)
    func protocolDelegateFuncThree(val:Array<String>) -> String
}

class PABViewController: ZyBaseViewController {

    var delegate:ProtocolDelegate?
    
    typealias PABClosure = (NSInteger) -> (String)
    var pabClosure:PABClosure?
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        // Do any additional setup after loading the view.
        let  btnProtocol = UIButton.init(frame: CGRect(x:10, y:100, width:100, height:100))
        self.view.addSubview(btnProtocol)
        btnProtocol.setTitle("设置Protocol", for: UIControlState.normal)
        btnProtocol.backgroundColor = UIColor.black
        btnProtocol.addTarget(self, action: #selector(btnProtocolClick(btn:)), for: UIControlEvents.touchUpInside)
        
        let  btnClosure = UIButton.init(frame: CGRect(x:10, y:300, width:100, height:100))
        self.view.addSubview(btnClosure)
        btnClosure.setTitle("设置Closure", for: UIControlState.normal)
        btnClosure.backgroundColor = UIColor.black
        btnClosure.addTarget(self, action: #selector(btnClosureClick(btn:)), for: UIControlEvents.touchUpInside)
    }
    
    func btnProtocolClick(btn:UIButton) -> Void {
        if (self.delegate != nil) {
            self.delegate?.protocolDelegateFuncOne(val: "代理方法1")
            self.delegate?.protocolDelegateFuncTwo(val: ["key":"代理方法2"])
            let threeStr:String = (self.delegate?.protocolDelegateFuncThree(val: ["代理方法3"]))!
            print("这是代理方法3的返回值:\(threeStr)")
        }
        self.navigationController?.popViewController(animated: true)
    }
    
    func btnClosureClick(btn:UIButton) -> Void {
        if (self.pabClosure != nil) {
            let closureStr:String = self.pabClosure!(123456)
            print("闭包返回的值:\(closureStr)")
        }
        self.navigationController?.popViewController(animated: true)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
